<?php
error_reporting(0);
define('ROOT_PATH',dirname(__FILE__));
include('comm/config.php');
function iswriteable($file){ 
    if(is_dir($file)){  
	    $dir=$file;  
		if($fp = @fopen("$dir/test.txt", 'w')){   
		    @fclose($fp);   
			@unlink("$dir/test.txt");   
			$writeable = 1;  
		}
		else{   
		    $writeable = 0;
		} 
	}
	else
	{  
	    if($fp = @fopen($file, 'a+')){
			@fclose($fp);   $writeable = 1;  
		}
		else{
			$writeable = 0;  
		} 
	} 
	return $writeable;
}
$dirrole[] = array('name'=>'/data','old'=>'可写');
foreach($dirrole as $key => $value)
{
	$value['state'] = iswriteable(ROOT_PATH.$value['name']);
	$value['new'] = $value['state'] ? '可写' : '不可写';
	$dirrole[$key] = $value;
}
$state=true;
if(MYAPPKEY){
    $sql1="update ".$BIAOTOU."tradelist set checked=0,outer_code='' where outer_code='".MYAPPKEY."' or(outer_code='' and checked=2)";
}
if(APPKEY2){
    $sql2="update ".$BIAOTOU."tradelist set checked=0,outer_code='' where outer_code='".APPKEY2."' or(outer_code='' and checked=2)";
	mysql_query($sql2);
}
if(APPKEY3){
    $sql3="update ".$BIAOTOU."tradelist set checked=0,outer_code='' where outer_code='".APPKEY3."' or(outer_code='' and checked=2)";
	mysql_query($sql3);
}
if(APPKEY4){
    $sql4="update ".$BIAOTOU."tradelist set checked=0,outer_code='' where outer_code='".APPKEY4."' or(outer_code='' and checked=2)";
	mysql_query($sql4);
}
if(APPKEY5){
    $sql5="update ".$BIAOTOU."tradelist set checked=0,outer_code='' where outer_code='".APPKEY5."' or(outer_code='' and checked=2)";
	mysql_query($sql5);
}


$sql_arr = array (
	array (
		'msg' => '重置确认错误的订单',
		'sql' => $sql1
	)
);

if($_GET['step']==1){
	$i=0;
    foreach($sql_arr as $row){
        $sql=$row['sql'];
	    if(mysql_query($sql)){
			$msg[$i]['c']=$row['msg'].'成功<br/>';
			$msg[$i]['s']=1;
			$i++;
		}
        else{
			$msg[$i]['c']=$row['msg'].'失败<BR/><span style=" color:red">'.mysql_error().'</span>';
			$msg[$i]['s']=0;
			$i++;
		}
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>多多淘宝客 升级向导</title>
<link rel="stylesheet" href="http://soft.duoduo123.com/updateimages/style.css" type="text/css" media="all" />
</head>
<body>
<div class="container">
	<div class="header">
		<h1>duoduo淘客 升级文件</h1>
		<span>官方 <a href="http://soft.duoduo123.com" target="_blank">http://soft.duoduo123.com</a></span>
		<span style="margin-right:40px"> 简体中文 UTF8 版</span>	
		
		<div class="setup">
		<p>本次修复内容：</p>
        <p>重置确认错误的订单</p>
	</div>
	
</div>
<div class="main">
<?php if($_GET['step']==''){?>
<h2 class="title">目录、文件权限检查&nbsp;&nbsp; <span class="STYLE1">如何更改权限？</span> <a href="http://soft.duoduo123.com/help/other/2010/0809/98.html" target="_blank">查看</a></h2>
<table class="tb" style="margin:20px 0 20px 55px;">
	<tr>
	<th width="150px" >目录文件</th>
	<th width="150px" class="padleft"><div align="left">所需状态</div></th>
	<th width="280px" class="padleft">当前状态</th>
</tr>
<?php foreach($dirrole as $value):?>
<tr>
<td><?php echo $value['name'];?></td>
<td class="padleft"><?php echo $value['old'];?></td>
<td class="<?php echo $value['state'] ? 'w' : 'nw';?> pdleft1"><?php echo $value['new'];?></td>
</tr>
<?php if(!$value['state']){$state = false;}?>
<?php endforeach;?>
</table>
 
<h2 class="title">&nbsp;</h2>
<form action="" method="get" style="text-align:center">
<input type="hidden" name="step" value="1" />
<?php if($state==true){?>
<input type="submit" value="升 级">
<?php }else{?>
<input type="submit" value="升 级" disabled="disabled" id="next">
<?php }?>
</form>
<?php }else{?>
<table class="tb" style="margin:20px 0 20px 55px;">
<?php foreach($msg as $k=>$v){?>
<tr>
<td><?php echo $v['c'];?></td>
<?php if($v['s']==0){$state=false;}?>
</tr>
<?php }?>
</table>
<h2 class="title">&nbsp;</h2>
<form action="update.php" method="get" style="text-align:center">
<?php if($state==false){?>
<input type="submit" value="返 回">
<?php }else{?>
<a href="index.php" style="font-size:16px">完成</a>
<?php 
unlink("update.php");
unlink("data/update.lock");
}
?>
</form>
<?php }?>
    <div class="footer">&copy;2010 - 2011 <a href="http://soft.duoduo123.com/">soft.duoduo123.com</a></div>
  </div>
</div>
</body>
</html>
<?php mysql_close();?>